1
|
|
|
/** |
2
|
|
|
Copyright 2018 June Hanabi |
3
|
|
|
|
4
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); |
5
|
|
|
you may not use this file except in compliance with the License. |
6
|
|
|
You may obtain a copy of the License at |
7
|
|
|
|
8
|
|
|
http://www.apache.org/licenses/LICENSE-2.0 |
9
|
|
|
|
10
|
|
|
Unless required by applicable law or agreed to in writing, software |
11
|
|
|
distributed under the License is distributed on an "AS IS" BASIS, |
12
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13
|
|
|
See the License for the specific language governing permissions and |
14
|
|
|
limitations under the License. |
15
|
|
|
*/ |
16
|
|
|
/** |
17
|
|
|
* Adds the pug-loader inside Angular CLI's webpack config, if not there yet. |
18
|
|
|
* @see https://github.com/danguilherme/ng-cli-pug-loader |
19
|
|
|
*/ |
20
|
|
|
const fs = require('fs'); |
21
|
|
|
const commonCliConfig = 'node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/common.js'; |
22
|
|
|
const pugRule = '{ test: /.pug$/, use: [ { loader: "apply-loader" }, { loader: "pug-loader" } ] },'; |
23
|
|
|
|
24
|
|
|
fs.readFile(commonCliConfig, (err, data) => { |
25
|
|
|
if (err) { throw err; } |
26
|
|
|
|
27
|
|
|
const configText = data.toString(); |
28
|
|
|
// make sure we don't add the rule if it already exists |
29
|
|
|
if (configText.indexOf(pugRule) > -1) { return; } |
30
|
|
|
|
31
|
|
|
// Insert the pug webpack rule |
32
|
|
|
const position = configText.indexOf('rules: [') + 8; |
33
|
|
|
const output = [configText.slice(0, position), pugRule, configText.slice(position)].join(''); |
34
|
|
|
const file = fs.openSync(commonCliConfig, 'r+'); |
35
|
|
|
fs.writeFile(file, output, {}, () => { |
36
|
|
|
fs.close(file, () => { }); |
37
|
|
|
}); |
38
|
|
|
}); |
39
|
|
|
|